#coding = utf-8

from kuai.mol import *

def list_atom_pair12(mol):
    """The function try to list all atom pair of bonds in sequence"""
    result = []
    for i in mol.bonds:
        result.append([i.atom1, i.atom2])
    return result
        
def list_angle_atoms(mol):
    """The function try to list all atom pair of bonds in sequence"""
    result = []
    for i in mol.atoms:
        degree = mol.degree(i)
        for j in range(0, degree):
            for k in range(j+1, degree):
                result.append([mol.neighbors[i][j][0], i, mol.neighbors[i][k][0], ])
    return result


def list_atom_pair13(mol):
    pairs = [ [min(i[0], i[2]), max(i[0], i[2]),] \
               for i in list_angle_atoms(mol)]
    from sets import Set
    result = []
    for i in Set(pairs):    # use Set to remove duplicated pairs
        if mol.get_bond(i[0], i[1]) is None:
            result.append(i)
    return result
            
        
def list_torsion_atoms(mol):
    result = []
    for i in mol.bonds:
        d1 = mol.degree(i.atom1)
        d2 = mol.degree(i.atom2)
        for j1 in range(0, d1):
            for j2 in range(0, d2):
                a1 = mol.neighbors[i.atom1][j1][0]
                a2 = mol.neighbors[i.atom2][j2][0]
                if a1 != a2 and a1 != i.atom2 and a2 != i.atom1:
                    result.append([a1, i.atom1, i.atom2, a2, ])
    return result
                    

def list_atom_pair14(mol):
    pairs = [ [min(i[0], i[3]), max(i[0], i[3]),] \
               for i in list_torsion_atoms(mol)]
    from sets import Set
    result = []
    for i in Set(pairs):    # use Set to remove duplicated pairs
        if mol.get_bond(i[0], i[1]) is None and mol.get_angle_center(i[0], i[1]) is None:
            result.append(i)
    return result

def list_fork0_atoms(mol):
    result = []
    for i in mol.atoms:
        if mol.degree(i) == 3:
            result.append([i, mol.neighbors[i][0][0], mol.neighbors[i][1][0], mol.neighbors[i][2][0],])
    return result

def list_fork1_atoms(mol):
    result = []
    for i in mol.atoms:
        if mol.degree(i) == 3:
            result.append([mol.neighbors[i][0][0], i, mol.neighbors[i][1][0], mol.neighbors[i][2][0],])
    return result

def list_fork2_atoms(mol):
    result = []
    for i in mol.atoms:
        if mol.degree(i) == 3:
            result.append([mol.neighbors[i][0][0], mol.neighbors[i][1][0], i, mol.neighbors[i][2][0],])
    return result


def list_fork3_atoms(mol):
    result = []
    for i in mol.atoms:
        if mol.degree(i) == 3:
            result.append([mol.neighbors[i][0][0], mol.neighbors[i][1][0], mol.neighbors[i][2][0], i,])
    return result


def list_nonbond_atoms(mol):
    # TODO
    raise NotImplementedError()
    
    
def list_intramol_nonbond_atoms(mol):
    # TODO
    raise NotImplementedError()
    
    
def list_intermol_nonbond_atoms(mol):
    # TODO
    raise NotImplementedError()

